encode with null type falls back to runtime class